<template>
  <div class="diskInfoWrap">
      <el-form
          :inline="true"
          :model="searchParams"
          style="width: 100%;"
          size="small"
          class="formWrap"
      >
      <el-form-item label="启用状态" style="max-width: 240px;">
                <el-select style="width:160px" v-model="searchParams.select1" placeholder="请选择">
                    <el-option label="启用" value="0"></el-option>
                    <el-option label="停用" value="1"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="性质" style="max-width: 240px;">
                <el-select style="width:160px" v-model="searchParams.select2" placeholder="请选择">
                    <el-option label="税率" value="1"></el-option>
                    <el-option label="征收率" value="2"></el-option>
                </el-select>
            </el-form-item>
          <el-form-item
              label="税率/征收率 :"
              style="max-width: 340px"
          >
              <el-input
                  style="width: 160px"
                  v-model="searchParams.input3"
                  placeholder="请输入"
              >
            </el-input>
          </el-form-item>

          <el-form-item>
              <el-button type="primary" @click="onSubmit">查询</el-button>
              <el-button type="primary" @click="onResize">重置</el-button>
          </el-form-item>
      </el-form>

      <el-button
          type="primary"
          size="small"
          @click="getDiskInfo"
          style="margin: 4px 0"
          icon="el-icon-upload"
          v-if="hasAuth('VMS_AVALIBLE_TAX_RATE_ADD')"
      >
          获取可用税率信息
      </el-button>
      <el-button type="primary" @click="getHistoryDialogShow" size="small" style="margin: 0 4px 0 16px">
          获取记录
      </el-button>
      <el-button
          type="primary"
          @click="exportFn"
          size="small"
          v-if="hasAuth('VMS_ABALIBLE_TAX_RATE_EXPORT')"
      >
          导出
      </el-button>

      <tableList
          :showIndex="true"
          :loading="loading"
          border
          :heightMin="120"
          :total="pages.total"
          :keySet="keySet2"
          :tableData="listDetails2"
          :paginationShow="true"
          :pageNumber="pages.current"
          :pageSize="pages.size"
          @handleSizeChange="handleSizeChange"
          @handleCurrentChange="handleCurrentChange"
      >
        <template #slzsl="{row}">
            <div>
                {{ row.slzsl || 0 }}
            </div>
        </template>
      </tableList>



      <vxe-modal
          v-model="historyDialogShow"
          class="dialogClass"
          title="获取记录"
          width="80%"
          resize
          remember
      >
          <template v-slot>
              <getHistory v-if="historyDialogShow" source="availableTax" :heightMin="120"></getHistory>
          </template>
      </vxe-modal>
  </div>
</template>

<script>
import mixinTable from '@/mixin/mtable.js'
import getHistory from '../baseInfo/components/getHistory.vue'
import tableList from '@/components/tableList/index.vue'
import { exportVmsAvalibleTaxRate } from '@/api/fileDownload.js'
import { queryVmsAvalibleTaxRate, getVmsAvalibleTaxRateByLq } from '@/api/vmsAvalibleTaxRate.js'

export default {
  name: 'availableTax',
  mixins: [mixinTable],
  data() {
      return {
        historyDialogShow:false,

          listDetails2: [],
          keySet2: [
              {
                  label: '性质',
                  englishName: 'csxz',
              },
              {
                  label: '税率/征收率',
                  englishName: 'slzsl',
                  width: 240,
                  isSlot: true,
                  slotName: 'slzsl',
              },
              {
                  label: '原税率标志',
                  englishName: 'yslbz'
              },
              {
                  label: '对应原税率',
                  englishName: 'dyysl',
              },
              {
                  label: '状态',
                  englishName: 'cszt',
              },
              {
                  label: '有效期起',
                  englishName: 'yxqq',
              },
              {
                  label: '有效期止',
                  englishName: 'yxqz',
              },
              {
                  label: '停用日期',
                  englishName: 'tyrq',
              },
          ],
      }
  },
  methods: {
      onResize() {
          this.onResizeFn()
          this.getList()
      },
      onSubmit() {
        this.pages.current = 1;
          this.getList()
      },
      async getList() {
            this.loading = true
            let { data, code, message } = await queryVmsAvalibleTaxRate(
                {
                    "csxz": this.searchParams.select2,
                    "cszt": this.searchParams.select1,
                    pageNo: this.pages.current,
                    pageSize: this.pages.size,
                    "slzsl": this.searchParams.input3
                },
            )
            if (code == 200) {
                this.loading = false
                this.listDetails2 = data.records
                this.pages.total = data.total
                this.pages.current = data.current
                this.pages.size = data.size
            } else {
                this.loading = false
            }
      },
      getDiskInfo() {
          this.$alert('是否调用接口获取可用税率信息？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              showCancelButton: true,
              type: 'warning',
          })
              .then(async () => {
            let { data, code, message } = await getVmsAvalibleTaxRateByLq(
                {}
            )
            if (code == 200) {
                this.onResize()
            } else {
                // this.$message({
                //     type: 'error',
                //     message: message,
                // })
            }
              })
              .catch(() => {
                  this.$message({
                      type: 'info',
                      message: '已取消',
                  })
              })
      },
      getHistoryDialogShow() {
          this.historyDialogShow = true;
      },
      exportFn() {
        exportVmsAvalibleTaxRate({
                "csxz": this.searchParams.select2,
                "cszt": this.searchParams.select1,
                pageNo: this.pages.current,
                pageSize: this.pages.size,
                "slzsl": this.searchParams.input3
            })
      },
  },
  created(){
    this.getList()
  },
  components: {
      tableList,
      getHistory
  },
}
</script>

<style lang = "scss" scoped>
@import '@/style/variables.scss';
.diskInfoWrap {
  box-sizing: border-box;
//   padding: 10px;
  .head {
      display: flex;
      height: 14px;
      align-items: center;
      margin-bottom: 12px;
      .colCLas {
          width: 4px;
          height: 100%;
          background-color: $allBg;
          margin-right: 12px;
      }
      .info {
          height: 100%;
          display: flex;
          align-items: center;
      }
  }
  .formWrap{
    ::v-deep .el-form-item--small.el-form-item{
        margin-bottom: 0px;
    }
  }
}
</style>
